package com.demo.service.impl;


import com.alibaba.excel.EasyExcel;
import com.demo.config.DataListener;
import com.demo.config.TaskPoolConfig;
import com.demo.dto.ExcelReportDto;
import com.demo.service.FileService;
import com.demo.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
public class FileServiceImpl implements FileService {
    @Autowired
    private ReportService reportService;
    @Autowired
    private TaskPoolConfig taskPoolConfig;

    @Override
    public void readeExcel(MultipartFile file) throws IOException {
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(file.getInputStream(), ExcelReportDto.class, new DataListener(reportService, taskPoolConfig)).sheet().doRead();
    }
}
